package fileIO;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class FileStreamTest {
	public static void main(String[] args) throws IOException {
		test1();
		test3();
		test2();
	}

	private static void test3() throws IOException {
		FileOutputStream out = 
			new FileOutputStream("/home/tarena/Desktop/3.txt",true);
		byte[] b = {50,51,52};
		out.write(b,1,2);
		out.close();
		
	}

	private static void test2() throws IOException {
		FileInputStream in = new FileInputStream("/home/tarena/Desktop/3.txt");
		System.out.println(in.available());
		System.out.println(in.getChannel());
		System.out.println(in.getFD());
		in.skip(2);
		byte by[] = new byte[2];
		System.out.println(in.read(by));
		System.out.println(by[0]);
		int b;
		while((b=in.read())!=-1){
			System.out.println(b);
		}
		in.close();
	}

	private static void test1() throws IOException {
		FileOutputStream out = 
			new FileOutputStream("/home/tarena/Desktop/3.txt");//文件没有会新建，目录不存在会抛异常
		out.write(97);
		out.write(98);
		byte[] b = {99,100,101};
		out.write(b);
		out.close();
	}
	
	
}
